<template>
	<view class="classlist">
		<view class="loadingLayout" v-if="!classList.length && !noData">
			<uni-load-more status="loading"></uni-load-more>
		</view>
		<view class="content">
			<navigator :url="'/pages/preview/preview?id='+item._id" class="item" v-for="item in classList" :key="item._id" >
				<image :src="item.smallPicurl" mode="aspectFill"></image>
			</navigator>
		</view>
		<view class="loadingLayout" v-if="classList.length || noData">
			<uni-load-more :status="noData?'noMore':'loading'"></uni-load-more>
		</view>
		<!-- <view class="safe-area-inset-bottom"></view> -->
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import api from '@/api/api';
	import { defineProps } from 'vue';
	import {onLoad,onReachBottom,onShareAppMessage,onShareTimeline} from '@dcloudio/uni-app'
	import {goToHome} from '@/utils/common.js'
	//查询对象
	const queryParams = {pageNum:1,pageSize:20}; //最多一页返回二十个壁纸
	//展示列表
	const classList = ref([]);
	//是否触底
	const noData = ref(false);
	//页面的名字
	let pageName;
	//获取展示列表
	const getWalllist = async (queryParams) =>{
		var resp;
		if(queryParams.classid) await api.getWalllist(queryParams).then(res=>resp = res);
	 	if(queryParams.type)  await api.userWallList(queryParams).then(res=>resp = res);
		classList.value = [... classList.value,... resp.data.data];
		if(queryParams.pageSize > resp.data.data.length) noData.value = true;
		uni.setStorageSync("storgClassList",classList.value); //往本地存
	}
	//从跳转的url中获取信息
	onLoad(e=>{
		//解构
		let {classid=null,name=null,type=null} = e;
		//先处理页面名字
		pageName = name;
		uni.setNavigationBarTitle({
			title:name
		});
		if(type) queryParams.type = type;
		if(classid) queryParams.classid = classid;
		if(!classid&&!type) goToHome(); 
		getWalllist(queryParams); //发请求
		
		
		
	});
	//如果滑动到底
	onReachBottom(()=>{
		if(noData.value) return;
		queryParams.pageNum++;//页数加1
		getWalllist(queryParams);
	});
	//分享给好友
	onShareAppMessage(e=>{
		return {
			title:"郝子的小壁纸",
			path:'/pages/classlist/classlist?id='+queryParams.classid+"&name="+pageName
		}
	});
	//分享朋友圈
	onShareTimeline(()=>{
		return {
			title:'郝子的壁纸'+pageName,
			imageUrl:'/static/classify2.jpg',
			query:'id='+queryParams.classid+"&name="+pageName
		}
	});
	
</script>

<style lang="scss" scoped>
.classlist{
	padding:5rpx;
	box-sizing: border-box;
	.content{
		display: grid;
		grid-template-columns: repeat(3,1fr);
		gap:5rpx;
		.item{
			height: 440rpx;
			image{
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
}
</style>
